package com.ucode.hrm.service.impl;

import cn.hutool.core.util.ObjUtil;
import com.ucode.hrm.mapper.HrmEmployeeCompensationMapper;
import com.ucode.hrm.mapper.HrmEmployeeMapper;
import com.ucode.hrm.service.HrmEmployeeCompensationService;
import com.ucode.model.hrm.HrmEmployee;
import com.ucode.model.hrm.HrmEmployeeCompensation;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class HrmEmployeeCompensationServiceImpl implements HrmEmployeeCompensationService {

    @Resource
    private HrmEmployeeCompensationMapper hrmEmployeeCompensationMapper;
    @Resource
    private HrmEmployeeMapper hrmEmployeeMapper;

    @Override
    public HrmEmployeeCompensationMapper initMapper() {
        return hrmEmployeeCompensationMapper;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int save(HrmEmployeeCompensation compensation) {
        int i = hrmEmployeeCompensationMapper.save(compensation);
        if(i > 0 && ObjUtil.isNotNull(compensation.getSocialSecurityDate())){
            HrmEmployee updateBean = new HrmEmployee();
            updateBean.setId(compensation.getId());
            updateBean.setSspStartTime(compensation.getSocialSecurityDate());
            hrmEmployeeMapper.update(updateBean);
        }
        return i;
    }
}
